package com.timothy.asset.base;

import org.apache.log4j.PropertyConfigurator;

import java.io.InputStream;
import java.util.Properties;

/**
 * Created with IntelliJ IDEA.
 * User: qtang
 * Date: 9/21/12
 * Time: 1:38 PM
 * To change this template use File | Settings | File Templates.
 */
public class Initialize {
    private final static String PROPERTY_FILE_NAME = "config.properties";
    private static Initialize initialize = null;
    private Properties agproperties = null;
    private boolean initSuccessfully = false;

    public static synchronized Initialize getInstance() {
        if (initialize == null) {
            initialize = new Initialize(PROPERTY_FILE_NAME);
        }
        return initialize;
    }

    public String getPropertyValue(String key) {
        return agproperties.getProperty(key);
    }

    public boolean isInitSuccessfully() {
        return initSuccessfully;
    }

    private Initialize(String propFile) {
        try {
            agproperties = new Properties();
            InputStream in = this.getClass().getClassLoader().getResourceAsStream(propFile);
            agproperties.load(in);
            initLog();
            in.close();
            initSuccessfully = true;
        } catch (Exception ignored) {
        }
    }



    private void initLog() {
        PropertyConfigurator.configure(agproperties);
    }
}
